<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Authorization extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
	}
	
	public function Index()
	{
		echo "Moo Motherfucker";
		//$this->json->Error(1, "Please login or something....");
	}

	public function Register()
	{
		$email = $this->input->post('email');
		$password = $this->input->post('password');
		$name = $this->input->post('name');

		$return = $this->auth->Register($email, $password, $name);
		if($return == FALSE)
			echo $this->json->GetJsonResult(0, 1, "Error registering user", null);
		else
			echo $this->json->GetJsonResult(1, 0, "User have been registered", null);
	}

	public function Login()
	{
		$email = $this->input->post('email');
		$password = $this->input->post('password');

		$result = $this->auth->Login($email, $password);

		if($result == TRUE)
		{
			echo $this->json->GetJsonResult(1, 0, "User been logged in", null);
		}
		else
		{
			echo $this->json->GetJsonResult(0, 1, "Error logging user in", null);
		}
	}

	public function Logout()
	{
		$this->auth->Logout();
		echo $this->json->GetJsonResult(1, 0, "User been logged out", null);
	}
}

?>